package net.flintx.array;

/**
 * Created by flintx on 2018/1/10.
 */
public class MissingNumber {
    public int missingNumber(int[] nums) {
        int sum = 0;
        for (int num :
                nums) {
            sum += num;
        }
        int n = nums.length;
        return n * (n + 1) / 2 - sum;
    }

    public int betterMethod(int[] nums) {
        int xor = 0;
        for (int i = 0; i < nums.length; i++) {
            xor = xor ^ i ^ nums[i];
        }
        return xor ^ nums.length;
    }

}
